<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="nblank"/>
</head>
<body>
<div class="content container">
	<h2 class="page-title">用户管理<small> 用户${not empty user.id?'修改':'添加'}</small></h2>
<section class="widget widget-tabs widget-table-overflow ">
	<header>
		<ul class="nav nav-tabs">
			<li><a href="${ctx}/sys/user/list">用户列表</a></li>
			<li class="active"><a href="javacript:;">用户<shiro:hasPermission name="sys:user:edit">${not empty user.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:user:edit">查看</shiro:lacksPermission></a></li>
		</ul>
	</header>
		<div class="body tab-content">
	<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/user/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<%--<div class="form-group">--%>
			<%--<label class="control-label col-sm-4">头像:</label>--%>
			<%--<div class="col-sm-4">--%>
				<%--<form:hidden id="nameImage" path="photo" htmlEscape="false" maxlength="255" class="input-xlarge"/>--%>
				<%--<sys:ckfinder input="nameImage" type="images" uploadPath="/photo" selectMultiple="false" maxWidth="100" maxHeight="100"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<div class="form-group">
			<label class="control-label col-sm-4">归属公司:</label>
			<div class="col-sm-4">
                <sys:treeselect id="company" name="company.id" value="${user.company.id}" labelName="company.name" labelValue="${user.company.name}"
					title="公司" url="/sys/office/treeData?type=1" cssClass="form-control input-transparent" notAllowSelectRoot="true"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4">归属部门:</label>
			<div class="col-sm-4">
                <sys:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}"
					title="部门" url="/sys/office/treeData?type=2" cssClass="form-control input-transparent" notAllowSelectRoot="true" notAllowSelectParent="false"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 工号:</label>
			<div class="col-sm-4">
				<form:input path="no" htmlEscape="false" maxlength="50" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"<span><span style="color:red;">*</span></span> 姓名:</label>
			<div class="col-sm-4">
				<form:input path="name" htmlEscape="false" maxlength="50" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 登录名:</label>
			<div class="col-sm-4">
				<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
				<form:input path="loginName" htmlEscape="false" maxlength="50" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 密码:</label>
			<div class="col-sm-4">

				<c:if test="${empty user.id}"><input id="newPassword" name="newPassword" type="password" value="" required maxlength="50" minlength="5" class="form-control input-transparent"/></c:if>
				<c:if test="${not empty user.id}"><input id="newPassword" name="newPassword" type="password" value="" maxlength="50" minlength="5" class="form-control input-transparent"/><span class="help-inline">若不修改密码，请留空。</span></c:if>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 确认密码:</label>
			<div class="col-sm-4">
				<c:if test="${empty user.id}"><input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="50" minlength="5" equalTo="#newPassword" class="form-control input-transparent"/></c:if>
                <c:if test="${not empty user.id}"><input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="50" minlength="5" equalTo="#newPassword" class="form-control input-transparent"/></c:if>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4">邮箱:</label>
			<div class="col-sm-4">
				<form:input path="email" htmlEscape="false" maxlength="100" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4">电话:</label>
			<div class="col-sm-4">
				<form:input path="phone" htmlEscape="false" maxlength="100" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span>手机:</label>
			<div class="col-sm-4">
				<form:input path="mobile" htmlEscape="false" maxlength="100" class="form-control input-transparent"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 是否允许登录:</label>
			<div class="col-sm-4">
				<form:select path="loginFlag" data-style="btn-primary" data-width="auto" class="selectpicker">
					<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
						<form:option value="${dict.value}" label="${dict.label}"/>
					</c:forEach>
				</form:select>
				“是”代表此账号允许登录，“否”则表示此账号不允许登录
			</div>
		</div>
		<div class="form-group hide">
			<label class="control-label col-sm-4">用户类型:</label>
			<div class="col-sm-4">
				<form:select path="userType" data-style="btn-primary" data-width="auto" class="selectpicker">
					<c:forEach items="${fns:getDictList('sys_user_type')}" var="dict">
						<form:option value="${dict.value}" label="${dict.label}"/>
					</c:forEach>
				</form:select>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4"><span><span style="color:red;">*</span></span> 用户角色:</label>
			<div class="col-sm-4">
				<div class="checkbox checkbox-primary">
				<form:checkboxes path="roleIdList" items="${allRoles}" itemLabel="name" itemValue="id" htmlEscape="false" class="checkbox-primary"/>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-4">备注:</label>
			<div class="col-sm-4">
				<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control input-transparent"/>
			</div>
		</div>
		<c:if test="${not empty user.id}">
			<div class="form-group">
				<label class="control-label col-sm-4">创建时间:</label>
				<div class="col-sm-4">
					<label class="lbl"><fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/></label>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-4">最后登录:</label>
				<div class="col-sm-4">
					<label class="lbl">IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate value="${user.loginDate}" type="both" dateStyle="full"/></label>
				</div>
			</div>
		</c:if>
		<div class="form-actions">
			<div class="text-align-center">
				<input id="btnCancel" class="btn btn-default" type="button" style="margin-left: -50px;min-width:100px;" value="返 回" onclick="history.go(-1)"/>
				<input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;" type="submit" value="保 存"/>&nbsp;
			</div>
		</div>
	</form:form>
			</div>
		</section>
</div>
<script type="text/javascript">
    $(document).ready(function() {
		$.validator.addMethod("isMobile", function(value, element) {
			var length = value.length;
			var regPhone = /^1([3578]\d|4[57])\d{8}$/;
			return this.optional(element) || ( length == 11 && regPhone.test( value ) );
		}, "请正确填写您的手机号码");

		$("#no").focus();
        $("#inputForm").validate({
            rules: {
                loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')},
				mobile: {
					required: true,
					isMobile: true
				}
            },
            messages: {
                loginName: {remote: "用户登录名已存在"},
                confirmNewPassword: {equalTo: "输入与上面相同的密码"},
				mobile:"请正确填写您的手机号码"
            },
            submitHandler: function(form){
                loading('正在提交，请稍等...');
                form.submit();
            },
            errorContainer: "#messageBox",
            errorPlacement: function(error, element) {
                $("#messageBox").text("输入有误，请先更正。");
                if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                    error.appendTo(element.parent().parent());
                } else {
                    error.insertAfter(element);
                }
            }
        });
    });
</script>
</body>
</html>